const fs = require('fs')
const path = require("path");
function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  css: {
    loaderOptions: {
      sass: {
        prependData: fs.readFileSync('src/assets/style/variable.scss', 'utf-8')
      }
    }
  },
  pluginOptions: {
    electronBuilder: {
      builderOptions: {
        "appId": "com.bjsteam-bjstoolkit-forest-secret",
        "productName": "Forest Secret",
        'nsis': {
          'installerIcon': 'public/static/icon/plant_1_256.ico',
          'installerHeader': 'public/static/icon/plant_1_256.ico',
          'installerHeaderIcon': 'public/static/icon/plant_1_256.ico',
          'oneClick': false,
          'allowToChangeInstallationDirectory': true,
          'runAfterFinish': false
        },
        'win': {
          'target': 'nsis',
          'icon': 'public/static/icon/plant_1_256.ico',
          'legalTrademarks': 'http://www.baidu.com/'
        },
        "extraResources": [
          "./extraResources/**",
          {
            "from":"public/static/icon/",
            "to": "./icon/"
          }
        ]
      }
    }
  },
  chainWebpack(config) {
    // 第一步：让其他svg loader不要对src/assets/imgs/svgs进行操作
    config.module
        .rule('svg')
        .exclude.add(resolve('src/assets/svg'))
        .end();
    // 第二步：使用svg-sprite-loader 对 src/assets/imgs/svgs下的svg进行操作
    config.module
        .rule('icons')
        .test(/\.svg$/)
        .include.add(resolve('src/assets/svg'))
        .end()
        .use('svg-sprite-loader')
        .loader('svg-sprite-loader')
        .options({
          symbolId: 'icon-[name]'
        })
        .end()
  }
}
